#include "addcontact.h"
#include "ui_addcontact.h"
#include "network.h"
#include "clientHandler.h"
#include <QObject>
#include <QApplication>
#include <QKeyEvent>

addContact::addContact(QWidget *parent) :
        QDialog(parent),
        m_ui(new Ui::addContact)
{
    m_ui->setupUi(this);
    this->setWindowTitle("Add Contact");

    connect(m_ui->add, SIGNAL(clicked()), this, SLOT(clickedAddContact()));
    connect(ClientHandler::clientHandlerInstance(),SIGNAL(closeAddWindow()), this, SLOT(closeAddContact()));
}

addContact::~addContact()
{
    delete m_ui;
}

void addContact::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void addContact::clickedAddContact()
{
    //    ClientHandler::clientHandlerInstance()->setUsername(getUsername());
    //    if (getScreenName() != NULL)
    ClientHandler::clientHandlerInstance()->setScreenName(getScreenName());
    //    else
    ClientHandler::clientHandlerInstance()->setEmail(getEmail());
    ClientHandler::clientHandlerInstance()->sendAddContact();

}

void addContact::closeAddContact()
{
    this->close();
    return;

}


QString addContact::getScreenName()
{
    return m_ui->screenName->text();
}


QString addContact::getEmail()
{
    return m_ui->email->text();
}

void addContact::errorLabelUpdate()
{
    m_ui->errorLabel->setText(tr("<FONT COLOR=red>***Error*** Please try again.</FONT>"));
    m_ui->errorLabel->show();
}



void addContact::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Return)
    {
        clickedAddContact();
    }
}

